package model

import (
	"io"
	"net/http"
	"encoding/json"
	"git.oschina.net/YPTArch/apigateway/lib"
)


const (
	Ok                  = 200 //Ok 成功
	BadRequest          = 400 //请求失败
	Unauthorized        = 401 //验证失败
	InternalServerError = 500 //服务器内部错误

)

//Result ...
//返回结果结构
//Code  错误码
//Msg   返回信息
//Date  返回数据
type Result struct {
	Code int
	Msg  string
	Data interface{}
}


func GetModelsByUrl(url, requestType string, data io.Reader, header http.Header) *Result {
	res := lib.HttpRequest(url, requestType, data, header)
	if res == nil {
		return nil
	}
	resModel := &Result{}
	err := json.Unmarshal(res, resModel)
	if err != nil {
		lib.HandleError("model","GetModelsByUrl",err)
		return nil
	}
	return resModel
}